﻿using System.Windows;
using System.Windows.Controls;

namespace DependencyPropertySample
{
    /// <summary>
    /// 自定义 Textbox
    /// </summary>
    internal class CustomTextbox : TextBox
    {
        #region 依赖属性
        // 使用 propdp 来快速创建一个依赖属性
        public bool IsHighlighted
        {
            get { return (bool)GetValue(IsHighlightedProperty); }
            set { SetValue(IsHighlightedProperty, value); }
        }

        public static readonly DependencyProperty IsHighlightedProperty =
            DependencyProperty.Register(name: "IsHighlighted",                                  // 依赖属性名
                                        propertyType: typeof(bool),                             // 依赖属性类型
                                        ownerType: typeof(CustomTextbox),                       // 对应的类型
                                        typeMetadata: new PropertyMetadata(false));  // 默认值，回调等等
        #endregion

        #region 只读依赖属性

        //public static readonly DependencyProperty HasTextProperty;

        //public static readonly DependencyPropertyKey HasTextPropertyKey;

        //static CustomTextbox()
        //{
        //    HasTextPropertyKey = DependencyProperty.RegisterReadOnly(name: "HasText",
        //                                        propertyType: typeof(bool),
        //                                        ownerType: typeof(CustomTextbox),
        //                                        typeMetadata: new PropertyMetadata(false));
        //    HasTextProperty = HasTextPropertyKey.DependencyProperty;
        //}

        #endregion
    }
}
